home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / amiga / gui / x / xfig.lha / src / x11 / u_markers.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-26  |  13.5 KB  |  463 lines

  1. /*
  2.  * FIG : Facility for Interactive Generation of figures
  3.  * Copyright (c) 1985 by Supoj Sutanthavibul
  4.  *
  5.  * "Permission to use, copy, modify, distribute, and sell this software and its
  6.  * documentation for any purpose is hereby granted without fee, provided that
  7.  * the above copyright notice appear in all copies and that both the copyright
  8.  * notice and this permission notice appear in supporting documentation. 
  9.  * No representations are made about the suitability of this software for 
  10.  * any purpose.  It is provided "as is" without express or implied warranty."
  11.  */
  12.  
  13. #include "fig.h"
  14. #include "resources.h"
  15. #include "object.h"
  16. #include "mode.h"
  17. #include "paintop.h"
  18. #include "w_zoom.h"
  19.  
  20. #define set_marker(win,x,y,w,h,z1,z2) \
  21.     zXDrawRectangle(tool_d,(win),gccache[INV_PAINT],(x),(y),(w),(h))
  22.  
  23. #ifdef notdef
  24. /* not used in present implementation */
  25. static u_int    marker_pattern[3] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
  26.  
  27. mpr_static(pmarker, 5, 5, 1, marker_pattern);
  28. #endif
  29.  
  30. center_marker(x, y)
  31.     int            x, y;
  32. {
  33.     pw_vector(canvas_win, x, y - 2, x, y + 2, INV_PAINT, 1,
  34.           RUBBER_LINE, 0.0, DEFAULT_COLOR);
  35.     pw_vector(canvas_win, x - 2, y, x + 2, y, INV_PAINT, 1,
  36.           RUBBER_LINE, 0.0, DEFAULT_COLOR);
  37. }
  38.  
  39. toggle_csrhighlight(x, y)
  40.     int            x, y;
  41. {
  42.     set_line_stuff(1, RUBBER_LINE, 0.0, (INV_PAINT), DEFAULT_COLOR);
  43.     set_marker(canvas_win, x - 2, y - 2, 5, 5, 0, 0);
  44.     set_marker(canvas_win, x - 1, y - 1, 3, 3, 0, 0);
  45. }
  46.  
  47. ellipse_in_mask()
  48. {
  49.     return (cur_objmask & M_ELLIPSE);
  50. }
  51.  
  52. arc_in_mask()
  53. {
  54.     return (cur_objmask & M_ARC);
  55. }
  56.  
  57. compound_in_mask()
  58. {
  59.     return (cur_objmask & M_COMPOUND);
  60. }
  61.  
  62. anytext_in_mask()
  63. {
  64.     return ((cur_objmask & M_TEXT_NORMAL) || (cur_objmask & M_TEXT_HIDDEN));
  65. }
  66.  
  67. validtext_in_mask(t)
  68.     F_text       *t;
  69. {
  70.     return ((hidden_text(t) && (cur_objmask & M_TEXT_HIDDEN)) ||
  71.         ((!hidden_text(t)) && (cur_objmask & M_TEXT_NORMAL)));
  72. }
  73.  
  74. anyline_in_mask()
  75. {
  76.     return ((cur_objmask & M_POLYLINE_LINE) ||
  77.         (cur_objmask & M_POLYLINE_POLYGON) ||
  78.         (cur_objmask & M_POLYLINE_BOX));
  79. }
  80.  
  81. validline_in_mask(l)
  82.     F_line       *l;
  83. {
  84.     return ((((l->type == T_BOX) ||
  85.           (l->type == T_ARC_BOX)) && (cur_objmask & M_POLYLINE_BOX)) ||
  86.         ((l->type == T_EPS_BOX) && (cur_objmask & M_POLYLINE_BOX)) ||
  87.         ((l->type == T_POLYLINE) && (cur_objmask & M_POLYLINE_LINE)) ||
  88.         ((l->type == T_POLYGON) && (cur_objmask & M_POLYLINE_POLYGON)));
  89. }
  90.  
  91. anyspline_in_mask()
  92. {
  93.     return ((cur_objmask & M_SPLINE_O_NORMAL) ||
  94.         (cur_objmask & M_SPLINE_O_INTERP) ||
  95.         (cur_objmask & M_SPLINE_C_NORMAL) ||
  96.         (cur_objmask & M_SPLINE_C_INTERP));
  97. }
  98.  
  99. validspline_in_mask(s)
  100.     F_spline       *s;
  101. {
  102.     return (((s->type == T_OPEN_INTERP) && (cur_objmask & M_SPLINE_O_INTERP)) ||
  103.     ((s->type == T_OPEN_NORMAL) && (cur_objmask & M_SPLINE_O_NORMAL)) ||
  104.       ((s->type == T_CLOSED_INTERP) && (cur_objmask & M_SPLINE_C_INTERP)) ||
  105.        ((s->type == T_CLOSED_NORMAL) && (cur_objmask & M_SPLINE_C_NORMAL)));
  106. }
  107.  
  108. mask_toggle_ellipsemarker(e)
  109.     F_ellipse       *e;
  110. {
  111.     if (ellipse_in_mask())
  112.     toggle_ellipsemarker(e);
  113. }
  114.  
  115. mask_toggle_arcmarker(a)
  116.     F_arc       *a;
  117. {
  118.     if (arc_in_mask())
  119.     toggle_arcmarker(a);
  120. }
  121.  
  122. mask_toggle_compoundmarker(c)
  123.     F_compound       *c;
  124. {
  125.     if (compound_in_mask())
  126.     toggle_compoundmarker(c);
  127. }
  128.  
  129. mask_toggle_textmarker(t)
  130.     F_text       *t;
  131. {
  132.     if (validtext_in_mask(t))
  133.     toggle_textmarker(t);
  134. }
  135.  
  136. mask_toggle_linemarker(l)
  137.     F_line       *l;
  138. {
  139.     if (validline_in_mask(l))
  140.     toggle_linemarker(l);
  141. }
  142.  
  143. mask_toggle_splinemarker(s)
  144.     F_spline       *s;
  145. {
  146.     if (validspline_in_mask(s))
  147.     toggle_splinemarker(s);
  148. }
  149.  
  150. toggle_markers()
  151. {
  152.     toggle_markers_in_compound(&objects);
  153. }
  154.  
  155. toggle_markers_in_compound(cmpnd)
  156.     F_compound       *cmpnd;
  157. {
  158.     F_ellipse       *e;
  159.     F_arc       *a;
  160.     F_line       *l;
  161.     F_spline       *s;
  162.     F_text       *t;
  163.     F_compound       *c;
  164.     register int    mask;
  165.  
  166.     mask = cur_objmask;
  167.     if (mask & M_ELLIPSE)
  168.     for (e = cmpnd->ellipses; e != NULL; e = e->next)
  169.         toggle_ellipsemarker(e);
  170.     if ((mask & M_TEXT_NORMAL) || (mask & M_TEXT_HIDDEN))
  171.     for (t = cmpnd->texts; t != NULL; t = t->next) {
  172.         if ((hidden_text(t) && (mask & M_TEXT_HIDDEN)) ||
  173.         ((!hidden_text(t)) && (mask & M_TEXT_NORMAL)))
  174.         toggle_textmarker(t);
  175.     }
  176.     if (mask & M_ARC)
  177.     for (a = cmpnd->arcs; a != NULL; a = a->next)
  178.         toggle_arcmarker(a);
  179.     if ((mask & M_POLYLINE_LINE) ||
  180.     (mask & M_POLYLINE_POLYGON) ||
  181.     (mask & M_POLYLINE_BOX))
  182.     for (l = cmpnd->lines; l != NULL; l = l->next) {
  183.         if ((((l->type == T_BOX) ||
  184.           (l->type == T_ARC_BOX)) && (mask & M_POLYLINE_BOX)) ||
  185.         ((l->type == T_EPS_BOX) && (mask & M_POLYLINE_BOX)) ||
  186.         ((l->type == T_POLYLINE) && (mask & M_POLYLINE_LINE)) ||
  187.         ((l->type == T_POLYGON) && (mask & M_POLYLINE_POLYGON)))
  188.         toggle_linemarker(l);
  189.     }
  190.     if ((mask & M_SPLINE_O_NORMAL) || (mask & M_SPLINE_O_INTERP) ||
  191.     (mask & M_SPLINE_C_NORMAL) || (mask & M_SPLINE_C_INTERP))
  192.     for (s = cmpnd->splines; s != NULL; s = s->next) {
  193.         if (((s->type == T_OPEN_INTERP) && (mask & M_SPLINE_O_INTERP)) ||
  194.         ((s->type == T_OPEN_NORMAL) && (mask & M_SPLINE_O_NORMAL)) ||
  195.          ((s->type == T_CLOSED_INTERP) && (mask & M_SPLINE_C_INTERP)) ||
  196.         ((s->type == T_CLOSED_NORMAL) && (mask & M_SPLINE_C_NORMAL)))
  197.         toggle_splinemarker(s);
  198.     }
  199.     if (mask & M_COMPOUND)
  200.     for (c = cmpnd->compounds; c != NULL; c = c->next)
  201.         toggle_compoundmarker(c);
  202. }
  203.  
  204. update_markers(mask)
  205.     int            mask;
  206. {
  207.     F_ellipse       *e;
  208.     F_arc       *a;
  209.     F_line       *l;
  210.     F_spline       *s;
  211.     F_text       *t;
  212.     F_compound       *c;
  213.     register int    oldmask, newmask;
  214.  
  215.     oldmask = cur_objmask;
  216.     newmask = mask;
  217.     if ((oldmask & M_ELLIPSE) != (newmask & M_ELLIPSE))
  218.     for (e = objects.ellipses; e != NULL; e = e->next)
  219.         toggle_ellipsemarker(e);
  220.     if (((oldmask & M_TEXT_NORMAL) != (newmask & M_TEXT_NORMAL)) ||
  221.     ((oldmask & M_TEXT_HIDDEN) != (newmask & M_TEXT_HIDDEN)))
  222.     for (t = objects.texts; t != NULL; t = t->next) {
  223.         if ((hidden_text(t) &&
  224.          ((oldmask & M_TEXT_HIDDEN) != (newmask & M_TEXT_HIDDEN))) ||
  225.         ((!hidden_text(t)) &&
  226.          ((oldmask & M_TEXT_NORMAL) != (newmask & M_TEXT_NORMAL))))
  227.         toggle_textmarker(t);
  228.     }
  229.     if ((oldmask & M_ARC) != (newmask & M_ARC))
  230.     for (a = objects.arcs; a != NULL; a = a->next)
  231.         toggle_arcmarker(a);
  232.     if (((oldmask & M_POLYLINE_LINE) != (newmask & M_POLYLINE_LINE)) ||
  233.     ((oldmask & M_POLYLINE_POLYGON) != (newmask & M_POLYLINE_POLYGON)) ||
  234.     ((oldmask & M_POLYLINE_BOX) != (newmask & M_POLYLINE_BOX)))
  235.     for (l = objects.lines; l != NULL; l = l->next) {
  236.         if ((((l->type == T_BOX) ||
  237.           (l->type == T_ARC_BOX || l->type == T_EPS_BOX)) &&
  238.           ((oldmask & M_POLYLINE_BOX) != (newmask & M_POLYLINE_BOX))) ||
  239.         ((l->type == T_POLYLINE) &&
  240.         ((oldmask & M_POLYLINE_LINE) != (newmask & M_POLYLINE_LINE))) ||
  241.         ((l->type == T_POLYGON) &&
  242.          ((oldmask & M_POLYLINE_POLYGON) != (newmask & M_POLYLINE_POLYGON))))
  243.         toggle_linemarker(l);
  244.     }
  245.     if (((oldmask & M_SPLINE_O_NORMAL) != (newmask & M_SPLINE_O_NORMAL)) ||
  246.     ((oldmask & M_SPLINE_O_INTERP) != (newmask & M_SPLINE_O_INTERP)) ||
  247.     ((oldmask & M_SPLINE_C_NORMAL) != (newmask & M_SPLINE_C_NORMAL)) ||
  248.     ((oldmask & M_SPLINE_C_INTERP) != (newmask & M_SPLINE_C_INTERP)))
  249.     for (s = objects.splines; s != NULL; s = s->next) {
  250.         if (((s->type == T_OPEN_INTERP) &&
  251.          ((oldmask & M_SPLINE_O_INTERP) !=
  252.           (newmask & M_SPLINE_O_INTERP))) ||
  253.         ((s->type == T_OPEN_NORMAL) &&
  254.          ((oldmask & M_SPLINE_O_NORMAL) !=
  255.           (newmask & M_SPLINE_O_NORMAL))) ||
  256.         ((s->type == T_CLOSED_INTERP) &&
  257.          ((oldmask & M_SPLINE_C_INTERP) !=
  258.           (newmask & M_SPLINE_C_INTERP))) ||
  259.         ((s->type == T_CLOSED_NORMAL) &&
  260.          ((oldmask & M_SPLINE_C_NORMAL) !=
  261.           (newmask & M_SPLINE_C_NORMAL))))
  262.         toggle_splinemarker(s);
  263.     }
  264.     if ((oldmask & M_COMPOUND) != (newmask & M_COMPOUND))
  265.     for (c = objects.compounds; c != NULL; c = c->next)
  266.         toggle_compoundmarker(c);
  267.     cur_objmask = newmask;
  268. }
  269.  
  270. toggle_ellipsemarker(e)
  271.     F_ellipse       *e;
  272. {
  273.     set_line_stuff(1, RUBBER_LINE, 0.0, (INV_PAINT), DEFAULT_COLOR);
  274.     set_marker(canvas_win, e->start.x - 2, e->start.y - 2, 5, 5, 0, 0);
  275.     set_marker(canvas_win, e->end.x - 2, e->end.y - 2, 5, 5, 0, 0);
  276.     if (e->tagged)
  277.     toggle_ellipsehighlight(e);
  278. }
  279.  
  280. toggle_ellipsehighlight(e)
  281.     F_ellipse       *e;
  282. {
  283.     set_line_stuff(1, RUBBER_LINE, 0.0, (INV_PAINT), DEFAULT_COLOR);
  284.     set_marker(canvas_win, e->start.x, e->start.y, 1, 1, 0, 0);
  285.     set_marker(canvas_win, e->start.x - 1, e->start.y - 1, 3, 3, 0, 0);
  286.     set_marker(canvas_win, e->end.x, e->end.y, 1, 1, 0, 0);
  287.     set_marker(canvas_win, e->end.x - 1, e->end.y - 1, 3, 3, 0, 0);
  288. }
  289.  
  290. toggle_arcmarker(a)
  291.     F_arc       *a;
  292. {
  293.     set_line_stuff(1, RUBBER_LINE, 0.0, (INV_PAINT), DEFAULT_COLOR);
  294.     set_marker(canvas_win, a->point[0].x - 2, a->point[0].y - 2, 5, 5, 0, 0);
  295.     set_marker(canvas_win, a->point[1].x - 2, a->point[1].y - 2, 5, 5, 0, 0);
  296.     set_marker(canvas_win, a->point[2].x - 2, a->point[2].y - 2, 5, 5, 0, 0);
  297.     if (a->tagged)
  298.     toggle_archighlight(a);
  299. }
  300.  
  301. toggle_archighlight(a)
  302.     F_arc       *a;
  303. {
  304.     set_line_stuff(1, RUBBER_LINE, 0.0, (INV_PAINT), DEFAULT_COLOR);
  305.     set_marker(canvas_win, a->point[0].x, a->point[0].y, 1, 1, 0, 0);
  306.     set_marker(canvas_win, a->point[0].x - 1, a->point[0].y - 1, 3, 3, 0, 0);
  307.     set_marker(canvas_win, a->point[1].x, a->point[1].y, 1, 1, 0, 0);
  308.     set_marker(canvas_win, a->point[1].x - 1, a->point[1].y - 1, 3, 3, 0, 0);
  309.     set_marker(canvas_win, a->point[2].x, a->point[2].y, 1, 1, 0, 0);
  310.     set_marker(canvas_win, a->point[2].x - 1, a->point[2].y - 1, 3, 3, 0, 0);
  311. }
  312.  
  313. toggle_textmarker(t)
  314.     F_text       *t;
  315. {
  316.     int            dx, dy;
  317.  
  318.     set_line_stuff(1, RUBBER_LINE, 0.0, (INV_PAINT), DEFAULT_COLOR);
  319.     /* adjust for text angle */
  320.     dy = (int) ((double) t->height * cos(t->angle));
  321.     dx = (int) ((double) t->height * sin(t->angle));
  322.     set_marker(canvas_win, t->base_x - dx - 2, t->base_y - dy - 2, 5, 5, 0, 0);
  323.     set_marker(canvas_win, t->base_x - 2, t->base_y - 2, 5, 5, 0, 0);
  324.     if (t->tagged)
  325.     toggle_texthighlight(t);
  326. }
  327.  
  328. toggle_texthighlight(t)
  329.     F_text       *t;
  330. {
  331.     int            dx, dy;
  332.  
  333.     set_line_stuff(1, RUBBER_LINE, 0.0, (INV_PAINT), DEFAULT_COLOR);
  334.     /* adjust for text angle */
  335.     dy = (int) ((double) t->height * cos(t->angle));
  336.     dx = (int) ((double) t->height * sin(t->angle));
  337.     set_marker(canvas_win, t->base_x - dx, t->base_y - dy, 1, 1, 0, 0);
  338.     set_marker(canvas_win, t->base_x - dx - 1, t->base_y - dy - 1, 3, 3, 0, 0);
  339.     set_marker(canvas_win, t->base_x, t->base_y, 1, 1, 0, 0);
  340.     set_marker(canvas_win, t->base_x - 1, t->base_y - 1, 3, 3, 0, 0);
  341. }
  342.  
  343. toggle_all_compoundmarkers()
  344. {
  345.     F_compound       *c;
  346.     for (c=objects.compounds; c!=NULL ; c=c->next)
  347.     toggle_compoundmarker(c);
  348. }
  349.  
  350. toggle_compoundmarker(c)
  351.     F_compound       *c;
  352. {
  353.     set_line_stuff(1, RUBBER_LINE, 0.0, (INV_PAINT), DEFAULT_COLOR);
  354.     set_marker(canvas_win, c->nwcorner.x - 2, c->nwcorner.y - 2, 5, 5, 0, 0);
  355.     set_marker(canvas_win, c->secorner.x - 2, c->secorner.y - 2, 5, 5, 0, 0);
  356.     set_marker(canvas_win, c->nwcorner.x - 2, c->secorner.y - 2, 5, 5, 0, 0);
  357.     set_marker(canvas_win, c->secorner.x - 2, c->nwcorner.y - 2, 5, 5, 0, 0);
  358.     if (c->tagged)
  359.     toggle_compoundhighlight(c);
  360. }
  361.  
  362. toggle_compoundhighlight(c)
  363.     F_compound       *c;
  364. {
  365.     set_line_stuff(1, RUBBER_LINE, 0.0, (INV_PAINT), DEFAULT_COLOR);
  366.     set_marker(canvas_win, c->nwcorner.x, c->nwcorner.y, 1, 1, 0, 0);
  367.     set_marker(canvas_win, c->nwcorner.x - 1, c->nwcorner.y - 1, 3, 3, 0, 0);
  368.     set_marker(canvas_win, c->secorner.x, c->secorner.y, 1, 1, 0, 0);
  369.     set_marker(canvas_win, c->secorner.x - 1, c->secorner.y - 1, 3, 3, 0, 0);
  370.     set_marker(canvas_win, c->nwcorner.x, c->secorner.y, 1, 1, 0, 0);
  371.     set_marker(canvas_win, c->nwcorner.x - 1, c->secorner.y - 1, 3, 3, 0, 0);
  372.     set_marker(canvas_win, c->secorner.x, c->nwcorner.y, 1, 1, 0, 0);
  373.     set_marker(canvas_win, c->secorner.x - 1, c->nwcorner.y - 1, 3, 3, 0, 0);
  374. }
  375.  
  376. toggle_linemarker(l)
  377.     F_line       *l;
  378. {
  379.     F_point       *p;
  380.     int            fx, fy, x, y;
  381.  
  382.     set_line_stuff(1, RUBBER_LINE, 0.0, (INV_PAINT), DEFAULT_COLOR);
  383.     p = l->points;
  384.     fx = p->x;
  385.     fy = p->y;
  386.     for (p = p->next; p != NULL; p = p->next) {
  387.     x = p->x;
  388.     y = p->y;
  389.     set_marker(canvas_win, x - 2, y - 2, 5, 5, 0, 0);
  390.     }
  391.     if (x != fx || y != fy || l->points->next == NULL) {
  392.     set_marker(canvas_win, fx - 2, fy - 2, 5, 5, 0, 0);
  393.     }
  394.     if (l->tagged)
  395.     toggle_linehighlight(l);
  396. }
  397.  
  398. toggle_linehighlight(l)
  399.     F_line       *l;
  400. {
  401.     F_point       *p;
  402.     int            fx, fy, x, y;
  403.  
  404.     set_line_stuff(1, RUBBER_LINE, 0.0, (INV_PAINT), DEFAULT_COLOR);
  405.     p = l->points;
  406.     fx = p->x;
  407.     fy = p->y;
  408.     for (p = p->next; p != NULL; p = p->next) {
  409.     x = p->x;
  410.     y = p->y;
  411.     set_marker(canvas_win, x, y, 1, 1, 0, 0);
  412.     set_marker(canvas_win, x - 1, y - 1, 3, 3, 0, 0);
  413.     }
  414.     if (x != fx || y != fy) {
  415.     set_marker(canvas_win, fx, fy, 1, 1, 0, 0);
  416.     set_marker(canvas_win, fx - 1, fy - 1, 3, 3, 0, 0);
  417.     }
  418. }
  419.  
  420. toggle_splinemarker(s)
  421.     F_spline       *s;
  422. {
  423.     F_point       *p;
  424.     int            fx, fy, x, y;
  425.  
  426.     set_line_stuff(1, RUBBER_LINE, 0.0, (INV_PAINT), DEFAULT_COLOR);
  427.     p = s->points;
  428.     fx = p->x;
  429.     fy = p->y;
  430.     for (p = p->next; p != NULL; p = p->next) {
  431.     x = p->x;
  432.     y = p->y;
  433.     set_marker(canvas_win, x - 2, y - 2, 5, 5, 0, 0);
  434.     }
  435.     if (x != fx || y != fy) {
  436.     set_marker(canvas_win, fx - 2, fy - 2, 5, 5, 0, 0);
  437.     }
  438.     if (s->tagged)
  439.     toggle_splinehighlight(s);
  440. }
  441.  
  442. toggle_splinehighlight(s)
  443.     F_spline       *s;
  444. {
  445.     F_point       *p;
  446.     int            fx, fy, x, y;
  447.  
  448.     set_line_stuff(1, RUBBER_LINE, 0.0, (INV_PAINT), DEFAULT_COLOR);
  449.     p = s->points;
  450.     fx = p->x;
  451.     fy = p->y;
  452.     for (p = p->next; p != NULL; p = p->next) {
  453.     x = p->x;
  454.     y = p->y;
  455.     set_marker(canvas_win, x, y, 1, 1, 0, 0);
  456.     set_marker(canvas_win, x - 1, y - 1, 3, 3, 0, 0);
  457.     }
  458.     if (x != fx || y != fy) {
  459.     set_marker(canvas_win, fx, fy, 1, 1, 0, 0);
  460.     set_marker(canvas_win, fx - 1, fy - 1, 3, 3, 0, 0);
  461.     }
  462. }
  463.